package hygprs

import "errors"

/*
调度客户端登录包
A0 02 32 02 00 01 A2
01 00 00 00 01
02 00 01 86 A1
F1 00 00 00 0D
F1 00 00 00 19
...
00 00 8E 58 A1
*/

type ClientLoginParser struct {
	base
}

func ParseClientLogin(data []byte) (*ClientLoginParser, error) {
	if len(data) < 22 {
		return nil, errors.New("数据包过短")
	}
	return &ClientLoginParser{base{data: data}}, nil
}

func (e *ClientLoginParser) GetLineID() uint32 {
	return ToUint32(e.data[8:12])
}

func (e *ClientLoginParser) GetBusID() uint32 {
	return ToUint32(e.data[13:17])
}

func (e *ClientLoginParser) GetListenLines() map[uint32]struct{} {
	var res = make(map[uint32]struct{})
	data := e.data[17 : len(e.data)-5]
	for i := 0; i < len(data)/5; i++ { //解析监控的线路
		a := i * 5
		res[ToUint32(data[a+1:a+5])] = struct{}{}
	}
	return res
}
